package com.intretech.umsin.common.utils;

import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @version V1.0
 * @ClassName: ModuleHelper
 * @Description: ModuleHelper 用于VO,DTO互转
 * @author: 李启联
 * @date: 2022-04-15 16:16
 * @Copyright: Copyright (c) 2022
 */
public class ModuleHelper {

    private static final ModelMapper modelMapper;

    static {
        modelMapper = new ModelMapper();
//        modelMapper.createTypeMap(String.class, Date.class);
//        modelMapper.addConverter(toStringDate);
//        modelMapper.getTypeMap(String.class, Date.class).setProvider(localDateProvider);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
    }

    private ModuleHelper() {
    }

    public static <D, T> D map(final T entity, Class<D> outClass) {
        return modelMapper.map(entity, outClass);
    }

    public static <D, T> List<D> mapAll(final Collection<T> entityList, Class<D> outCLass) {
        return entityList.stream()
                .map(entity -> map(entity, outCLass))
                .collect(Collectors.toList());
    }

    public static <S, D> D map(final S source, D destination) {
        modelMapper.map(source, destination);
        return destination;
    }

}
